def is_number_prime(a_number):
    if a_number > 1:
        for num in range(2, (a_number // 2) + 1):
            if a_number % num == 0:
                return False
        return True
    else:
        return False


number = int(input("Введите число: "))
if number <= 0 or not 1000 <= number <= 9999:
    print(0)
else:
    max_prime_number = 0
    str_number = str(number)
    count_iterations = 4
    for i in range(1, count_iterations + 1):
        current_index_str = 0
        while current_index_str + i <= len(str_number):
            a_part_number = int(str_number[current_index_str: current_index_str + i])
            if is_number_prime(a_part_number) and a_part_number > max_prime_number:
                max_prime_number = a_part_number

            current_index_str += 1

    print(max_prime_number)
